Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#947)
by
unknown
03:43
created

smr15.js ➔ showRaceInfo   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
(function() {
2
"use strict";
3
4
	window.voteSite = function(snUrl) {
5
		// Must not redirect the current page until after the external vote
6
		// site URL has been opened in a new tab. Use setTimeout to do this.
7
		setTimeout(function() {
8
			window.location = snUrl;
9
		}, 0);
10
	};
11
12
	function doCalc(type, number, totalDest) {
13
		var i = 1, total = 0, df=document.FORM;
14
		for(; i<=number; i++) {
15
			total += df[type+i].value * 1;
16
		}
17
		df[totalDest].value = total;
18
	};
19
20
	// Recalculate total number of ports, summing over level
21
	window.levelCalc = function(maxPortLevel) {
22
		doCalc('port', maxPortLevel, 'total');
23
	};
24
25
	// Recalculate sum of port race percentages
26
	window.raceCalc = function() {
27
		doCalc('race', 9, 'racedist');
28
	};
29
30
	// Set the total number of ports to zero
31
	window.setZero = function(maxPortLevel) {
32
		var df = document.FORM;
33
		for (var i=1; i<=maxPortLevel; i++) {
34
			df['port'+i].value = 0;
35
		}
36
		df.total.value = 0;
37
	};
38
39
	// Set the port race distribution to be equal
40
	window.setEven = function() {
41
		var i = 2, df=document.FORM;
42
		df.race1.value = 12;
43
		for(; i<=9; i++) {
44
			df['race'+i].value = 11;
45
		}
46
		df.racedist.value = 100;
47
	};
48
49
	var body, currentlyFlashing=false, flashColour, origColour, intervalFlash, timeoutStopFlash;
50
51
	function stopFlash() {
52
		clearInterval(intervalFlash);
53
		body.style.backgroundColor = origColour;
0 ignored issues
show
Bug introduced by
The variable body seems to be never initialized.
Loading history...
54
		currentlyFlashing = false;
55
	};
56
57
	function bgFlash() {
58
		var body = document.getElementsByTagName('body')[0];
59
		if(body.style.backgroundColor === origColour) {
60
			body.style.backgroundColor = flashColour;
61
		}
62
		else {
63
			body.style.backgroundColor = origColour;
64
		}
65
	};
66
67
	window.triggerAttackBlink = function(colour) {
68
		if(origColour == null) {
0 ignored issues
show
Best Practice introduced by
Comparing origColour to null using the == operator is not safe. Consider using === instead.
Loading history...
69
			origColour = document.getElementsByTagName('body')[0].style.backgroundColor;
70
		}
71
		flashColour = '#'+colour;
72
		clearTimeout(timeoutStopFlash);
73
		if (currentlyFlashing === false) {
74
			currentlyFlashing = true;
75
			//flash 3 times
76
			bgFlash();
77
			intervalFlash = setInterval(bgFlash,500);
78
		}
79
		timeoutStopFlash = setTimeout(stopFlash,3500);
80
	};
81
})();
82
83
// Used by shop_hardware.php
84
function recalcOnKeyUp(transaction, hardwareTypeID, cost) {
85
	var form = document.getElementById(transaction + hardwareTypeID);
86
	form.total.value = form.amount.value * cost;
87
}
88
89
// Used by planet_defense.php
90
function showWeaponInfo(select) {
91
	var target = $(select).data('target');
92
	var show = $("option:selected", select).data('show');
93
	$(target).children().addClass('hide');
94
	$(show).removeClass('hide');
95
}
96
97
// Used by game_join.php
98
function showRaceInfo(select) {
99
	var race_id = $("option:selected", select).val();
100
	document.getElementById('race_image').src = "images/race/race" + race_id + ".jpg";
101
	document.getElementById('graphframe').src = "images/race/graph/graph" + race_id + ".gif";
102
	var desc = document.getElementById('race_descr');
103
	$(desc).children().addClass('hide');
104
	$(".race_descr" + race_id, desc).removeClass('hide');
105
	createRaceRadarChart(race_id);
106
}
107
108
// Used by game_join.php 
109
function createRaceRadarChart(race_id) {
110
111
	var races = {
112
		1: [[1.0,  1.0,  1.0,  1.0,  1.0],  'Neutral',    '#FFD800'],
113
		2: [[5.2,  10.0, 5.8,  8.1,  5.2],  'Alskant',    '#FF00FF'],
114
		3: [[8.3,  5.0,  10.0, 3.3,  8.3],  'Creonti',    '#FF8000'],
115
		4: [[9.5,  4.9,  9.5,  7.7,  9.5],  'Human',      '#0000FF'],
116
		5: [[8.0,  6.1,  9.7,  10.0, 8.0],  'Ik\'Thorne', '#BFBFFF'],
117
		6: [[8.1,  4.7,  8.8,  4.3,  8.1],  'Salvene',    '#00AA00'],
118
		7: [[10.0, 5.7,  8.7,  9.1,  10.0], 'Thevian',    '#800000'],
119
		8: [[7.2, 6.3,   7.9,  6.2,  7.2],  'WQ Human',   '#804040'],
120
		9: [[9.5, 4.9,   8.0,  5.1,  9.5],  'Nijarin',    '#FF8080']
121
	};
122
	
123
	var data = [
124
		{
125
			type: 'scatterpolar',
126
			r: [1.0, 1.0, 1.0, 1.0, 1.0],
127
			theta: ['Hunting', 'Trading', 'Combat', 'Utility', 'Hunting'],
128
			fill: 'toself',
129
			name: 'Neutral',
130
			line: {color: '#FFD800'},
131
			title: {
132
				text: 'Neutral'
133
			}
134
		}
135
	];
136
137
	var layout = {
138
		showlegend: false,
139
		polar: {
140
			radialaxis: {
141
				visible: true,
142
				showgrid: true,
143
				range: [0, 11],
144
				color: '#fff',
145
			},
146
			bgcolor: '#111'
147
		},
148
		paper_bgcolor: '#06240E',
149
		plot_bgcolor: '#000',
150
		font: {
151
			color: '#fff'
152
		},
153
		coloraxis : '#000'
154
	};
155
	var check = document.getElementsByClassName('plotly');
156
	if (check.length == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing check.length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
157
		Plotly.newPlot('graphframe', data, layout, {staticPlot: true});
0 ignored issues
show
Bug introduced by
The variable Plotly seems to be never declared. If this is a global, consider adding a /** global: Plotly */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
158
	} 
159
	Plotly.animate('graphframe', {
160
		data: [{
161
			r: races[race_id][0],
162
			name: races[race_id][1],
163
			line: {color: races[race_id][2]},
164
		}],
165
		traces: [0],
166
		layout: {}
167
	}, {
168
		tansition: {
169
			duration: 500,
170
			easing: 'linear'
171
		},
172
		frame: {
173
			duration: 500
174
		}
175
	})
176
}
177
// Used by alliance_create.php and alliance_stat.php
178
function togglePassword(select) {
179
	var showPassword = $(select).val() === "password";
180
	// We need to both toggle the element display (for the user) and toggle the
181
	// disabled property (for the form submission).
182
	if (showPassword) {
183
		$("#password-display").show();
184
	} else {
185
		$("#password-display").hide();
186
	}
187
	$("#password-input").prop("disabled", !showPassword);
188
}
189